package com.csd.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import com.csd.dao.BaseDao;
import com.csd.util.HttpHelper;

/**
 * Servlet implementation class CityTimeServlet
 */
@WebServlet("/CityTimeServlet")
public class CityTimeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	doPost(request, response);
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("fsdfdsfsd");
		String beginTime = request.getParameter("beginTime");
		String endTime = request.getParameter("endTime");
		int cityId = Integer.parseInt(request.getParameter("cityID"));
		int tplaceid = Integer.parseInt(request.getParameter("tplaceid"));
		int orderby = Integer.parseInt(request.getParameter("orderby"));
		JSONObject obj = new JSONObject();
		obj.put("beginTime", beginTime);
		obj.put("endTime", endTime);
		obj.put("cityId", cityId);
		obj.put("tplaceid", tplaceid);
		obj.put("orderby", orderby);
		String carStr = HttpHelper.HttpPost(obj.toString(), BaseDao.CARS);
		JSONObject carJson = JSONObject.fromObject(carStr);
		String msg = carJson.getString("msg");
		int status = carJson.getInt("status");
		if(status == 0){
			JSONObject dataJson = JSONObject.fromObject(carJson.getString("data"));
			String taketime = dataJson.getString("taketime");
			String takehour = dataJson.getString("takehour");
			String takeminute = dataJson.getString("takeminute");
			String returntime = dataJson.getString("returntime");
			String returnhour = dataJson.getString("returnhour");
			String returnminute = dataJson.getString("returnminute");
			String takecityid = dataJson.getString("takecityid");
			String returncityid = dataJson.getString("returncityid");
			
		}else{
			PrintWriter ot = response.getWriter();
			ot.println("<script language=\"javaScript\">");
			ot.println("alert(" + msg + ");");
			ot.println(" window.location='CityTime.jsp'");
			ot.println("</script>");
		}
	}

}
